import * as THREE from 'three';

const RackMat2 = new THREE.MeshPhongMaterial({color:0xafc0ca});

/**
 * 架子类
 */
export default class Shelf {
    constructor(option) {
        console.log('架子类')

        this.parent = option._scene;

        this.storage = option.storage;
        this.storageZoneId=option.storageZoneId;
        this.shelfId=option.shelfId;
        this.shelfName=option.shelfName;
        this.plane_x=option.planeLength || 80;//货架板面长度
        this.plane_y=option.planeHeight || 2; //货架板面高度
        this.plane_z=option.planeWidth || 24;//货架板面宽度
        this.holder_x=option.holderLength || 2; //支架长度
        this.holder_z=option.holderWidth || 2; //支架宽度
        this.holder_y=option.holderHeight || 25; //支架高度
        this.x=option.x;
        this.y=option.y;
        this.z=option.z;
        this.layerNum=option.layerNum || 4; //货架层数
        this.columnNum=option.columnNum || 3; //货架每层列数
      
        this.addLayerOfShelf(option); // 生成架子
    }

    // 放置一叠货架
    addLayerOfShelf(option){
        for(var i = 0; i < this.layerNum; i++){
            let plane = new THREE.BoxGeometry( this.plane_x, this.plane_y, this.plane_z );
            for(let j = 0; j < this.layerNum; j++){
                let gy = this.y + this.plane_y*(this.layerNum) + (this.holder_y)*j;
                const RackMat = new THREE.MeshLambertMaterial();
                RackMat.map = option._cargo["warehouse/rack"];
                RackMat.needsUpdate = true;
                let obj = new THREE.Mesh( plane, RackMat );
                obj.position.set(this.x , gy, this.z ) ;
                this.parent.add(obj);
            }
            let holderHeight = this.plane_y*(this.layerNum) + this.holder_y*this.layerNum
            let holder = new THREE.BoxGeometry( this.holder_x, holderHeight, this.holder_z );
            let obj2 = new THREE.Mesh( holder, RackMat2, 0 );
            let obj3 = new THREE.Mesh( holder, RackMat2, 0 );
            let obj4 = new THREE.Mesh( holder, RackMat2, 0 );
            let obj5 = new THREE.Mesh( holder, RackMat2, 0 );
    
            let holderPosY = this.y+this.holder_y+this.layerNum*this.plane_y / 2;
            obj2.position.set(this.x-this.plane_x/2+this.holder_x/2,holderPosY,this.z+this.plane_z/2-this.holder_z/2);
            obj3.position.set(this.x+this.plane_x/2-this.holder_x/2,holderPosY,this.z+this.plane_z/2-this.holder_z/2);
            obj4.position.set(this.x-this.plane_x/2+this.holder_x/2,holderPosY,this.z-this.plane_z/2+this.holder_z/2);
            obj5.position.set(this.x+this.plane_x/2-this.holder_x/2,holderPosY,this.z-this.plane_z/2+this.holder_z/2);
            this.parent.add(obj2);
            this.parent.add(obj3);
            this.parent.add(obj4);
            this.parent.add(obj5);
        }
    }

    ///////////////////////////// 公共方法 /////////////////////////////
   
    update (_props) {
       
    };
    // On Window Resize
    onWindowResize (vpW, vpH, pixelRatio) {
        
    };
}